// pages/tax-simulate/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    income_total: null,
    bonus: null,
    cost_total: null,
    income_tax_free: null,
    cost_deduction: null,
    special_deduction: null,
    special_additional_deduction: null,
    other_deduction: null,
    donations: null,
    tax_deduction: null,
    tax_paid: null,
    loading: false,
    dialogContent: '',
    dialogTitle: '计算成功'
  },
  submitTax() {
    let that = this
    this.setData({loading: true})
    wx.request({
      url: 'http://happymovie.icu:9000/tax/tax',
      method: 'POST',
      data: {
        income_total: this.data.income_total,
        bonus: this.data.bonus,
        cost_total: this.data.cost_total,
        income_tax_free: this.data.income_tax_free,
        cost_deduction: this.data.cost_deduction,
        special_deduction: this.data.special_deduction,
        special_additional_deduction: this.data.special_additional_deduction,
        other_deduction: this.data.other_deduction,
        donations: this.data.donations,
        tax_deduction: this.data.tax_deduction,
        tax_paid: this.data.tax_paid
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      dataType: 'json',
      success (res) {
        // console.log(res.data)
        if (res.data.code === 200) {
          let pop_text = `合并计税方式应纳税额：${res.data.data.tax_combine}\n合并计税方式应退税额：${res.data.data.tax_combine_refundable}\n单独计税方式应纳税额：${res.data.data.tax_separate}\n单独计税方式应退税额：${res.data.data.tax_separate_refundable}`
          // console.log(pop_text)
          that.setData({
            dialogContent: pop_text,
            showDialog: true
          })
        } else {
          that.setData({
            dialogTitle: '计算失败',
            dialogContent: res.data.message,
            showDialog: true
          })
        }
      },
      complete () {
        that.setData({loading:false})
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})